﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Acoris.Markdown
{
    /// <summary>
    /// 表示一个AcorisML文档的读取器
    /// </summary>
    public sealed class AcorisMLReader
    {
        private string m_documentText;
        private int m_line;
        private int m_position;
        private int m_offset;
        private AcToken m_token;

        internal void Move(Predicate<char> condition)
        {
            var ch = m_documentText[m_offset];
            var length = m_documentText.Length;
            var newline = false;
            while (condition(ch) && m_offset < length)
            {
                if (ch == '\r') {
                    newline = true;
                }

                if(ch == '\n' && newline)
                {
                    m_line++;
                    newline = false;
                }
                m_offset++;
                m_position++;
            }
        }

        internal bool NameContract(char word)
        {
            switch (word)
            {
                case '\r': case '\n':case '\t':case '<':
                case '/':case '>':case '\"':case '=':return false;
                default:return true;
            }
        }

        public AcToken ReadStartTagName()
        {
            var startLine = this.m_line;
            var startPosition = this.m_position;
            Move(NameContract);
            var token = new AcToken(AcorisMLContract.Type.Element,startLine,this.m_line,startPosition,this.m_position,m_token);
            m_token = token;
            return token;
        }

        public AcToken ReadEndTagName()
        {
            return null;
        }

        public AcToken ReadAttributeName()
        {
            return null;
        }

        public AcToken ReadAttributeValue()
        {
            return null;
        }

        public AcToken ReadContent()
        {
            return null;

        }

        public AcToken ReadTransfferedSpace()
        {
            return null;
        }

        /// <summary>
        /// 
        /// </summary>
        public int Line {
            get {
                return m_line;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        public int Position {
            get {
                return m_position;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        public AcToken Token {
            get {
                return m_token;
            }
        }
    }
}
